<template>
	<view class="order-day-route-list">
		<view class="my-list2">
			<view class="ml-item" v-for="(o, index) in list" :key="index">
			  <view class="i-title" :data-obj="o.id">
				<view>
					<view class="tip-icon"></view>
					{{U.sedate(o.stime.date+' '+o.stime.time, o.etime.date+' '+o.etime.time)}}
				</view>
				
				<view class="i-btns" :style="{'margin-top': '0rpx'}">
					<view class="btn ok" @click="gotoUpdDayRoute(o)">修改</view>
				</view>
			  </view>
			</view>
		</view>
	</view>
</template> 

<script>
	export default {
		data() {
			return {
				list: []
			}
		},
		onLoad(e) {
			const that = this;
			
			getOrderDetail(e.orderNum);
			
			// 其他页面跳转回当前页刷新列表
			uni.$on('refOrderDayRouteList', () => {
				that.$nextTick(function(){
					getOrderDetail(e.orderNum);
				});
			});
		},
		onUnload() {
			// 移除监听
			uni.$off('refOrderDayRouteList', this.refOrderDayRouteList);
		},
		methods: {
			// 获取-订单详情
			getOrderDetail(orderNum){
				let res = this.$u.api.getOrderDetail({orderNum: orderNum});
				if(res.code == 1){
					let ds = [];
					res.dayRoutes.forEach(d => {
						let p = {};
						// 订单编号
						p.orderNum = o.orderNum;
						// 某天行程id
						p.id = d.id;
						// 行程开始时间
						p.stime = {
							date: d.setime.st.split(' ')[0],
							time: d.setime.st.split(' ')[1]
						};
						// 行程结束时间
						p.etime = {
							date: d.setime.et.split(' ')[0],
							time: d.setime.et.split(' ')[1]
						};
						// 开始地点
						p.spoint = d.spoint;
						// 上午行程
						p.amps = d.amps || [];
						// 午餐地点
						p.lunchPoint = d.lunchPoint;
						// 下午行程
						p.pmps = d.pmps || [];
						// 结束地点
						p.epoint = d.epoint;
						
						ds.push(p);
					});
					this.list = ds;
				}
			},
			// 导航-指定某天的行程-修改页面
			gotoUpdDayRoute(o){
				uni.navigateTo({
					url: '/order-man/upd-order/upd-order',
					events: {
						// 监听被打开页面传回的数据
						pageData: function(res){
							
						}	
					},
					success: function(res){
						// 将当前修改的天数行程传递给修改页面
						res.eventChannel.emit('pageData', { drCount: this.list.length, data: o });
					}
				});
			}
		}
	}
</script>

<style>

</style>
